﻿using System;
using System.Collections.Generic;
using System.Text;


namespace Tea.Parser {

    /// <summary>
    /// 表示一个执行本地函数。
    /// </summary>
    public class CallNative :Expression {

        /// <summary>
        /// 获取名字。
        /// </summary>
        public string Name {
            get;
            private set;
        }

        /// <summary>
        /// 获取本地函数。
        /// </summary>
        public Type Function {
            get;
            private set;
        }

        /// <summary>
        /// 获取参数。
        /// </summary>
        public ArgumentList Arguments {
            get;
            private set;
        }

        /// <summary>
        /// 结束位置。
        /// </summary>
        Location _endLocation;

        /// <summary>
        /// 获取结束位置。
        /// </summary>
        /// <value></value>
        public override Location EndLocation {
            get {
                return _endLocation;
            }
        }

        /// <summary>
        /// 初始化 <see cref="Tea.Parser.CallNative"/>  的新实例。
        /// </summary>
        /// <param name="name">名字。</param>
        /// <param name="function">本地函数。</param>
        /// <param name="arguments">参数。</param>
        /// <param name="startLocation">开始位置。</param>
        /// <param name="endLocation">结束位置。</param>
        public CallNative(string name, Type function, ArgumentList arguments, Location startLocation, Location endLocation)
            : base(startLocation) {
            Name = name;
            Function = function;
            Arguments = arguments;
            _endLocation = endLocation;
        }

        public override void Write(CodeWriter writer) {
            writer.Write(Name);
            Arguments.Write(writer);
        }

        public override string ToString() {
            return Name + Arguments.ToString();
        }

        [System.Diagnostics.DebuggerStepThrough]
        public override void Accept(IAstVisitor visitor) {
            visitor.VisitCallNative(this);
        }
    }

}
